<?php

    $metar_url = "http://www.aviationweather.gov/adds/dataserver_current/httpparam?dataSource=" . $_GET['type']. "&requestType=retrieve&format=xml&stationString=" . str_replace(" ", "%20", $_GET['stations']) . "&hoursBeforeNow=3";
	
    $taf_url = "http://www.aviationweather.gov/adds/dataserver_current/httpparam?dataSource=" . $_GET['type']. "&requestType=retrieve&format=xml&stationString=" . str_replace(" ", "%20", $_GET['stations']) . "&hoursBeforeNow=0.5&mostRecentForEachStation=true";

    $request_url = ($_GET['type'] == "metars") ? $metar_url : $taf_url;

    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, $request_url); 
    curl_setopt($ch, CURLOPT_HEADER, false); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
    $data = curl_exec($ch); 
    //$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); 
    curl_close($ch); 

	header("Content-Type:text/xml");
    echo $data;

?>